package com.whsr.readservice.service;

import com.whsr.readservice.dao.CategoryMapper;
import com.whsr.readservice.dto.CategoryRequest;
import com.whsr.readservice.vo.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryService {
    private static Logger logger = LoggerFactory.getLogger(CategoryService.class);

    @Autowired
    private CategoryMapper categoryMapper;

    public Map<String, Integer> getCategoryMap(){
        List<Category> categories = categoryMapper.selectCategoryByDataFlag(1);
        Map<String, Integer> categorieMap = new HashMap<>();
        for(Category category : categories){
            categorieMap.put(category.getName(), category.getId());
        }
        return categorieMap;
    }


    public List<Category> getCategoryByPid(Integer pId) {
        return categoryMapper.selectCategoryByPid(pId);
    }

    public List<CategoryRequest> getCategoryList(CategoryRequest categoryRequest) {
        return categoryMapper.selectCategoryList(categoryRequest);
    }

    public List<Map<String, Object>> getAllCategory() {
        return categoryMapper.getAllCategory();
    }
}
